package vip.xiaonuo.supplier.modular.base.delivery.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.base.delivery.entity.SupplierDelivery;
import vip.xiaonuo.supplier.modular.base.delivery.param.SupplierDeliveryAddParam;
import vip.xiaonuo.supplier.modular.base.delivery.param.SupplierDeliveryEditParam;
import vip.xiaonuo.supplier.modular.base.delivery.param.SupplierDeliveryIdParam;
import vip.xiaonuo.supplier.modular.base.delivery.param.SupplierDeliveryPageParam;
import vip.xiaonuo.supplier.modular.base.delivery.service.SupplierDeliveryService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 发货方式控制器
 *
 * @author Mr.wu
 * @date  2025/03/15 19:07
 */
@Tag(name = "发货方式控制器")
@RestController
@Validated
public class SupplierDeliveryController {

    @Resource
    private SupplierDeliveryService supplierDeliveryService;

    /**
     * 获取发货方式分页
     *
     * @author Mr.wu
     * @date  2025/03/15 19:07
     */
    @Operation(summary = "获取发货方式分页")
    @SaCheckPermission("/supplier/base/delivery/page")
    @GetMapping("/supplier/base/delivery/page")
    public CommonResult<Page<SupplierDelivery>> page(SupplierDeliveryPageParam supplierDeliveryPageParam) {
        return CommonResult.data(supplierDeliveryService.page(supplierDeliveryPageParam));
    }

    /**
     * 添加发货方式
     *
     * @author Mr.wu
     * @date  2025/03/15 19:07
     */
    @Operation(summary = "添加发货方式")
    @CommonLog("添加发货方式")
    @SaCheckPermission("/supplier/base/delivery/add")
    @PostMapping("/supplier/base/delivery/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierDeliveryAddParam supplierDeliveryAddParam) {
        supplierDeliveryService.add(supplierDeliveryAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑发货方式
     *
     * @author Mr.wu
     * @date  2025/03/15 19:07
     */
    @Operation(summary = "编辑发货方式")
    @CommonLog("编辑发货方式")
    @SaCheckPermission("/supplier/base/delivery/edit")
    @PostMapping("/supplier/base/delivery/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierDeliveryEditParam supplierDeliveryEditParam) {
        supplierDeliveryService.edit(supplierDeliveryEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除发货方式
     *
     * @author Mr.wu
     * @date  2025/03/15 19:07
     */
    @Operation(summary = "删除发货方式")
    @CommonLog("删除发货方式")
    @SaCheckPermission("/supplier/base/delivery/delete")
    @PostMapping("/supplier/base/delivery/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierDeliveryIdParam> supplierDeliveryIdParamList) {
        supplierDeliveryService.delete(supplierDeliveryIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取发货方式详情
     *
     * @author Mr.wu
     * @date  2025/03/15 19:07
     */
    @Operation(summary = "获取发货方式详情")
    @SaCheckPermission("/supplier/base/delivery/detail")
    @GetMapping("/supplier/base/delivery/detail")
    public CommonResult<SupplierDelivery> detail(@Valid SupplierDeliveryIdParam supplierDeliveryIdParam) {
        return CommonResult.data(supplierDeliveryService.detail(supplierDeliveryIdParam));
    }
}
